import AbstractService from "./AbstractService";

export default class Chat extends AbstractService{
  constructor(netService:any = null){
    super(netService)
  }
    
  /**
   * 查询客服表列
   * @returns 
   */
  public async getChatServicesList(){
    let path: string = '/customer/chat/customerService/list';
    let _data = this._decorateData({}, path, 'get');
    let configRet = await this._netService.commonGet(path, _data);
    return configRet;
  }
  /**
   * 
   * @param userId 被转接的客户ID
   * @param toEmployeeUserId 转接到的同事用户ID
   */
  public async transferChat(userId:string, toEmployeeUserId:string, remark:string = ''){
    let path: string = '/customer/chat/transferChat';
      // let type = Utils.isGroup(id) ? "jid" : 'userId';
      let _data = { userId, toEmployeeUserId, remark };
      _data = this._decorateData(_data, path);
      let configRet = await this._netService.commonPost(path, _data);
      return configRet;
  }

  public getLatestServicedChatList = async ()=>{
    // TODO 获取上次下线时间，根据下线时间获取离线消息
    let path = '/tigase/getLastChatList';
    let _data: any = { startTime:0, endTime:0, pageSize:0, onlyQueryChat:1 }
    //let _data: any = { startTime:0, endTime:0, pageSize:0 }
    _data = this._decorateData(_data, path);
    return this._netService.commonPost(path, _data);
  }

  /**
   * 结束公众号聊天 
   * @param mpUserId 公众号下面的用户ID
   * @returns 
   */
  public cancelChat = async (serviceId:number)=>{
    let path = '/user/chat/chatOver';
    let _data: any = { mpUserId:serviceId }
    _data = this._decorateData(_data, path,'get');
    return this._netService.commonGet(path, _data);
  }
  /**
   * 客服结束接待
   */
  public cancelChatByService = async( userId:number )=>{
    let path = '/customer/chat/chatOver';
    let _data: any = { userId }
    _data = this._decorateData(_data, path,'get');
    return this._netService.commonGet(path, _data);
  }
}
